//
//  HJDWenZhangViewController.m
//  常州红房子
//
//  Created by 胡金东 on 16/7/24.
//  Copyright © 2016年 胡金东. All rights reserved.
//

#import "HJDWenZhangViewController.h"
//#import "AFNetworking.h"
//#import "MJExtension.h"
#import "WXApi.h"
#import "HLActionSheet.h"
#define  Url @"http://61.147.79.28:8080/jeeba/app/toNews.do"

static NSString *kLinkURL = @"http://tech.qq.com/zt2012/tmtdecode/252.htm";
static NSString *kLinkTagName = @"WECHAT_TAG_JUMP_SHOWRANK";
static NSString *kLinkTitle = @"专访张小龙：产品之上的世界观";
static NSString *kLinkDescription = @"微信的平台化发展方向是否真的会让这个原本简洁的产品变得臃肿？在国际化发展方向上，微信面临的问题真的是文化差异壁垒吗？腾讯高级副总裁、微信产品负责人张小龙给出了自己的回复。";



@interface HJDWenZhangViewController ()

@end

@implementation HJDWenZhangViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithTarget:self action:@selector(popToPre) image:@"︿" HighImage:nil];
    self.navigationItem.rightBarButtonItem = [UIBarButtonItem itemWithTarget:self action:@selector(shareBtnClick) image:@"矢量智能对象" HighImage:nil];
    
    UIWebView *webView = [[UIWebView alloc]initWithFrame:CGRectMake(0, 0, HJDWidth, HJDHeight)];
    NSURL *url = [NSURL URLWithString:@"http://61.147.79.28:8080/jeeba/app/toNews.do"];
    
    NSLog(@"news==%d",self.newsModel.newsId);
    NSString *body = [NSString stringWithFormat: @"id=%d",self.newsModel.newsId];
//     NSLog(@"%d",self.newsModel.newsId);
    
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc]initWithURL:url];
    [request setHTTPMethod:@"POST"];
    [request setHTTPBody:[body dataUsingEncoding:NSUTF8StringEncoding]];
    [webView loadRequest:request];
    [self.view addSubview:webView];
}

-(void)popToPre
{
    [self dismissViewControllerAnimated:NO completion:nil];
}

-(void)shareBtnClick
{
    
    
    //创建发送对象实例
    //    SendMessageToWXReq *sendReq = [[SendMessageToWXReq alloc] init];
    //    sendReq.bText = NO;//不使用文本信息
    //    sendReq.scene = 1;//0 = 好友列表 1 = 朋友圈 2 = 收藏
    
    //        NSArray *titles = @[@"QQ",@"微博",@"微信",@"朋友圈",@"QQ空间"];
    NSArray *titles = @[@"微信",@"朋友圈"];
    //        NSArray *imageNames = @[@"qq",@"weiBo",@"wechat",@"moments",@"qzone"];
    NSArray *imageNames = @[@"wechat",@"moments"];
    HLActionSheet *sheet = [[HLActionSheet alloc] initWithTitles:titles iconNames:imageNames];
    [sheet showActionSheetWithClickBlock:^(int btnIndex) {
        NSLog(@"btnIndex:%d",btnIndex);
        if (btnIndex == 0) {
            if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"weixin://"]]) {
                
                SendMessageToWXReq *sendReq = [[SendMessageToWXReq alloc] init];
                sendReq.bText = NO;//不使用文本信息
                sendReq.scene = 0;
                //创建分享内容对象
                WXMediaMessage *urlMessage = [WXMediaMessage message];
                urlMessage.title = kLinkTitle;//分享标题
                urlMessage.description = kLinkDescription;//分享描述
                [urlMessage setThumbImage:[UIImage imageNamed:@"关于我们"]];//分享图片,使用SDK的setThumbImage方法可压缩图片大小
                
                //创建多媒体对象
                WXWebpageObject *webObj = [WXWebpageObject object];
                //    webObj.webpageUrl = kLinkURL;//分享链接
                
                webObj.webpageUrl = [NSString stringWithFormat:@"%@?id=%d",Url,self.newsModel.newsId];
                NSLog(@"%@",webObj.webpageUrl);
                NSLog(@"id===%d",self.newsModel.newsId);
                
                
                //完成发送对象实例
                urlMessage.mediaObject = webObj;
                sendReq.message = urlMessage;
                
                //发送分享信息
                [WXApi sendReq:sendReq];
            }else{
                [MBProgressHUD showError:@"你还没有安装微信,请安装微信"];
            }
        }else if (btnIndex == 1){
            if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"weixin://"]]) {
                
                SendMessageToWXReq *sendReq = [[SendMessageToWXReq alloc] init];
                sendReq.bText = NO;//不使用文本信息
                sendReq.scene = 1;
                //创建分享内容对象
                WXMediaMessage *urlMessage = [WXMediaMessage message];
                urlMessage.title = kLinkTitle;//分享标题
                urlMessage.description = kLinkDescription;//分享描述
                [urlMessage setThumbImage:[UIImage imageNamed:@"testImg"]];//分享图片,使用SDK的setThumbImage方法可压缩图片大小
                
                //创建多媒体对象
                WXWebpageObject *webObj = [WXWebpageObject object];
                //    webObj.webpageUrl = kLinkURL;//分享链接
                
                webObj.webpageUrl = [NSString stringWithFormat:@"%@?id=%d",Url,self.newsModel.newsId];
                NSLog(@"%@",webObj.webpageUrl);
                NSLog(@"id===%d",self.newsModel.newsId);
                
                
                //完成发送对象实例
                urlMessage.mediaObject = webObj;
                sendReq.message = urlMessage;
                
                //发送分享信息
                [WXApi sendReq:sendReq];
            }else{
                [MBProgressHUD showError:@"你还没有安装微信,请安装微信"];
            }
            
        }
        
        
    } cancelBlock:^{
        NSLog(@"取消");
    }];

}

@end
